home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / clipboard / clipboard.c < prev    next >
C/C++ Source or Header  |  1993-12-07  |  5KB  |  206 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "geom.h"
  4. #include "mibload.h"
  5. #include "clipboard.mib"
  6. #include "clip.h"
  7.  
  8. void cut_callback(Widget , XtPointer,
  9.     XmPushButtonCallbackStruct *);
  10. void copy_callback(Widget , XtPointer,
  11.     XmPushButtonCallbackStruct *);
  12. void paste_callback(Widget , XtPointer,
  13.     XmPushButtonCallbackStruct *);
  14. void delete_callback(Widget , XtPointer,
  15.     XmPushButtonCallbackStruct *);
  16.  
  17.  
  18. char  obj_name[1000];
  19. Geom *theObject;
  20. int   clipfull;
  21.  
  22. main(int argc, char **argv)
  23. {
  24.   XtAppContext    App;
  25.   Widget    TopLevel,
  26.         MainWindow,
  27.         CutButton,
  28.         CopyButton,
  29.         PasteButton,
  30.         DeleteButton,
  31.         DrawArea;
  32.  
  33.   int        no_mi;
  34.  
  35.   mib_Widget   *MainForm;
  36.   static String    fallbacks[] = {
  37.     "myprog*Foreground:            gray20", /*15*/
  38.     "myprog*Background:            gray70", /*80*/
  39.     "myprog*XmTextField.background:           DeepSkyBlue",
  40.     "myprog*fontList:\
  41.     -adobe-helvetica-medium-r-normal--14-100-100-100-p-76-iso8859-1",
  42.     NULL};
  43.  
  44.   no_mi = 0;                /* no motif interface if no_mi = 1 */
  45.  
  46.   clipfull = 0;
  47.   obj_name[0] = '\0';
  48.  
  49.  
  50.   /* initialize application top level widget */
  51.  
  52.   TopLevel = XtVaAppInitialize(&App, "myprog", NULL, 0,
  53.     &argc, argv, fallbacks, NULL);
  54.  
  55.  
  56.   /* configure resize policy of window */
  57.  
  58.   XtVaSetValues(TopLevel, XmNminWidth, 272, XmNminHeight, 172, NULL);
  59.  
  60.   /* create the application main window widget */
  61.  
  62.   MainWindow = XtCreateManagedWidget("MainWindow",
  63.     xmMainWindowWidgetClass, TopLevel, NULL, 0);
  64.  
  65.  
  66.   /* load the interface via the mib library */
  67.  
  68.   MainForm = mib_load_interface(MainWindow,
  69.     Root, MI_FROMSTRING);
  70. /*  MainForm = mib_load_interface(MainWindow, "mib/clipboard.mib", MI_FROMFILE);
  71. */
  72.  
  73.   if (MainForm == NULL)
  74.     exit(0);
  75.  
  76.   /* Set widget pointers to null before trying to find their instances */
  77.  
  78.   CutButton  = NULL;
  79.   CopyButton  = NULL;
  80.   PasteButton  = NULL;
  81.   DeleteButton  = NULL;
  82.   DrawArea = NULL;
  83.  
  84.   /* Do similarly when trying to find a widget named "CutButton" */
  85.  
  86.   if (!(CutButton = XtNameToWidget(MainForm->me, "CutButton")))
  87.     no_mi = 1;
  88.   if (!(CopyButton = XtNameToWidget(MainForm->me, "CopyButton")))
  89.     no_mi = 1;
  90.   if (!(PasteButton = XtNameToWidget(MainForm->me, "PasteButton")))
  91.     no_mi = 1;
  92.   if (!(DeleteButton = XtNameToWidget(MainForm->me, "DeleteButton")))
  93.     no_mi = 1;
  94.   if (!(DrawArea = XtNameToWidget(MainForm->me, "DrawingArea")))
  95.     no_mi = 1;
  96.  
  97.   /* if we found both widgets then add a callback to the button. This
  98.      is called whenever the user clicks the button. If there was no
  99.      button and/or no text box then we avoid adding the callback. */
  100.  
  101.   if (!no_mi)
  102.   {
  103.     XtAddCallback(CutButton, XmNactivateCallback, cut_callback, NULL);
  104.     XtAddCallback(CopyButton, XmNactivateCallback, copy_callback, NULL);
  105.     XtAddCallback(PasteButton, XmNactivateCallback, paste_callback, NULL);
  106.     XtAddCallback(DeleteButton, XmNactivateCallback, delete_callback, NULL);
  107.   }
  108.  
  109.  
  110.   /* Bring the application window up on the screen. */
  111.  
  112.   XtRealizeWidget(TopLevel);
  113.  
  114.   /* initialize visual clipboard  - mg library stuff (gl or vanilla-x)*/
  115.  
  116.   clipboard_init(MainForm->me);
  117.  
  118.   /* Begin main Intrinsics event loop */
  119.  
  120.   XtAppMainLoop (App);
  121.  
  122. }
  123.  
  124. void cut_callback(Widget w, XtPointer data, XmPushButtonCallbackStruct *cbs)
  125. {
  126.   char tmp;
  127.   int  count;
  128.  
  129.   fprintf(stdout,"(echo (real-id target))\n");
  130.   fflush(stdout);
  131.   tmp = '\0';
  132.   while (tmp != '\"')
  133.     tmp = (char)fgetc(stdin);
  134.   tmp = '\0';
  135.   count = 0;
  136.   while (tmp != '\"')
  137.   {
  138.     tmp = (char)fgetc(stdin);
  139.     obj_name[count] = tmp;
  140.     count++;
  141.   }
  142.  
  143.   obj_name[count-1] = '\0';
  144.    
  145.   fprintf(stdout,"(write geometry - target)\n");
  146.   fflush(stdout);
  147.   theObject = GeomFLoad(stdin, obj_name);
  148.  
  149.   fprintf(stdout,"(delete target)\n");
  150.   fflush(stdout);
  151.  
  152.   clipfull = 1;
  153.   redraw(w);
  154.  
  155. }
  156. void copy_callback(Widget w, XtPointer data, XmPushButtonCallbackStruct *cbs)
  157. {
  158.   char tmp;
  159.   int  count;
  160.  
  161.   fprintf(stdout,"(echo (real-id target))\n");
  162.   fflush(stdout);
  163.   tmp = '\0';
  164.   while (tmp != '\"')
  165.     tmp = (char)fgetc(stdin);
  166.   tmp = '\0';
  167.   count = 0;
  168.   while (tmp != '\"')
  169.   {
  170.     tmp = (char)fgetc(stdin);
  171.     obj_name[count] = tmp;
  172.     count++;
  173.   }
  174.  
  175.   obj_name[count-1] = '\0';
  176.  
  177.   fprintf(stdout,"(write geometry - target)");
  178.   fflush(stdout);
  179.   theObject = GeomFLoad(stdin, obj_name);
  180.  
  181.   clipfull = 1;
  182.   redraw(w);
  183.  
  184. }
  185.  
  186. void paste_callback(Widget w, XtPointer data, XmPushButtonCallbackStruct *cbs)
  187. {
  188.   if (clipfull == 0)
  189.     return;
  190.  
  191.   fprintf(stdout,"(new-geometry %s {",obj_name);
  192.   GeomFSave(theObject, stdout, obj_name);
  193.   fprintf(stdout,"})");
  194.   fflush(stdout);
  195.  
  196. }
  197.  
  198. void delete_callback(Widget w, XtPointer data, XmPushButtonCallbackStruct *cbs)
  199. {
  200.   char        tmp;
  201.  
  202.   fprintf(stdout,"(delete target)\n");
  203.   fflush(stdout);
  204.  
  205. }
  206.